package com.elh.nio.test3;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * socket传递数据
 *
 * @author liulei
 **/
public class Server {

    public static void main(String[] args) throws IOException {
        byte[] bytes = new byte[2048];
        ServerSocket serverSocket = new ServerSocket(8088);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        int read = 0;
        FileOutputStream pngOut = new FileOutputStream(new File("D:\\22.png"));
        while ((read = inputStream.read(bytes)) != -1) {
            pngOut.write(bytes, 0, read);
        }
        pngOut.close();
        socket.close();
        serverSocket.close();
    }

}
